<template>
  <div class="mod-user">
    <el-form :inline="true" :model="dataForm" @keyup.enter.native="getDataList()">
      <div class="seacrhMoney">
        <el-form-item>
          <div class="balance-searchMoney">
            支付单号
            <el-input class="input" v-model="dataForm.userName" placeholder="请输入支付单号"></el-input>
          </div>
        </el-form-item>
        <el-form-item>
          <div class="balance-searchMoney">
            支付时间
            <el-date-picker v-model="value1" type="daterange" :clearable='false' value-format="yyyy-MM-dd HH:mm:ss" class="input" start-placeholder="开始日期" end-placeholder="结束日期">
            </el-date-picker>
          </div>
        </el-form-item>
        <!-- <el-form-item>
          <div class="balance-searchMoney">
            物业账单周期

            <el-date-picker
              v-model="value2"
              type="monthrange"
              @change="TimeYue"
              value-format="yyyy-MM"
              start-placeholder="开始月份"
              end-placeholder="结束月份"
            >
            </el-date-picker>
          </div>
        </el-form-item> -->
        <el-form-item v-if="type==1">
          <div class="balance-searchMoney">
            订单类型
            <el-select v-model="value4" filterable placeholder="请选择">
              <el-option v-for="item in options2" :key="item.value" :label="item.label" :value="item.value">
              </el-option>
            </el-select>
          </div>
        </el-form-item>
        <el-form-item>
          <div class="balance-searchMoney">
            支付方式
            <el-select v-model="value3" filterable placeholder="请选择">
              <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value">
              </el-option>
            </el-select>
          </div>
        </el-form-item>
        <!-- <el-form-item>
          <div class="balance-searchMoney">
            结算状态

            <el-select
              v-model="value5"
              clearable
              @change="status1"
              filterable
              placeholder="请选择"
            >
              <el-option
                v-for="item in options1"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              >
              </el-option>
            </el-select>
          </div>
        </el-form-item> -->
      </div>
      <el-form-item>
        <el-button type="primary" @click="demand">查询</el-button>
        <el-button type="primary" @click="empty">清空</el-button>
      </el-form-item>
    </el-form>

    <!-- 表格 -->
    <div class="export">
      <div style="display: flex; justify-content: flex-end;margin-bottom:10px;">
        <el-button type="primary" @click="exportExcel()">导出Excel</el-button>
      </div>
      <el-table :data="dataList" v-loading="dataListLoading" element-loading-text="数据加载中" element-loading-spinner="el-icon-loading" element-loading-custom-class="loading_color" style="width: 100%;">
        <template slot="empty">
          <img class="machine" src="../../assets/img/machine.svg" alt="" />
          <div style="font-size: 14px; text-align: center">暂无数据</div>
        </template>
        <el-table-column prop="orderNo" width="120" header-align="center" align="center" label="订单编号">
          <template slot-scope="scope">
            <div size="small" type="danger">
              <div v-if="scope.row.billType == 1" size="small">{{scope.row.paySerialNbr}}</div>
              <div v-if="scope.row.billType == 3" size="small">{{ scope.row.orderNo}}</div>
            </div>
          </template>
        </el-table-column>
        <el-table-column prop="paySerialId" header-align="center" align="center" label="支付单号" width="100">
        </el-table-column>
        <!-- <el-table-column prop="" width="130" header-align="center" align="center" label="订单联系人">
        <template slot-scope="scope">
          <div size="small" type="danger">
            {{ scope.row.memberName }} /
            {{ scope.row.memberPhone }}
          </div>
        </template>
      </el-table-column> -->
        <el-table-column prop="billType" header-align="center" align="center" label="订单类型" width='100'>
          <template slot-scope="scope">
            <div size="small" type="danger">
              <div v-if="scope.row.billType == 1">物业费</div>
              <div v-if="scope.row.billType == 2">有偿工单</div>
              <div v-if="scope.row.billType == 3">到家服务</div>
            </div>
          </template>
        </el-table-column>
        <el-table-column prop="dealType" header-align="center" align="center" label="交易类型" width='100'>
          <template slot-scope="scope">
            <div v-if="scope.row.dealType == 0" size="small">收款</div>
            <div v-if="scope.row.dealType == 1" size="small">退款</div>
          </template>
        </el-table-column>
        <el-table-column prop="dealDes" width="100" header-align="center" align="center" label="交易描述">
        </el-table-column>
        <!-- <el-table-column prop="" header-align="center" align="center" label="交易时间" width='140'>
        <template slot-scope="scope">
          <div size="small" type="danger">
            {{ scope.row.startBillCycle }} -
            {{ scope.row.endBillCycle }}
          </div>
        </template>
      </el-table-column> -->
        <el-table-column prop="paymentFee" header-align="center" align="center" label="交易金额" width='100'>
          <template slot-scope="scope">
            <div>{{ scope.row.paymentFee | MoneyFormat }}</div>
          </template>
        </el-table-column>
        <el-table-column prop="serviceCharge" header-align="center" align="center" label="手续费(元)" width="100">
          <template slot-scope="scope">
            <div>{{ scope.row.serviceCharge | MoneyFormat  }}</div>
          </template>
        </el-table-column>
        <el-table-column prop="recordedAmount" header-align="center" align="center" label="入账金额(元)" width="100">
          <template slot-scope="scope">
            <div>{{ scope.row.recordedAmount | MoneyFormat  }}</div>
          </template>
        </el-table-column>
        <el-table-column prop="userAddress" header-align="center" align="center" label="用户地址" width='140'>
        </el-table-column>
        <el-table-column prop="" header-align="center" align="center" label="支付方式">
          <template slot-scope="scope">
            <div v-if="scope.row.paymentMethod == 1" size="small">微信</div>
            <div v-if="scope.row.paymentMethod == 2" size="small">支付宝</div>
            <div v-if="scope.row.paymentMethod == 3" size="small">云闪付</div>
            <div v-if="scope.row.paymentMethod == 4" size="small">快捷支付</div>
          </template>
        </el-table-column>
        <el-table-column prop="paymentTime" header-align="center" align="center" label="支付时间" width="100">
        </el-table-column>
        <el-table-column prop="platformType" header-align="center" align="center" label="支付终端">
        </el-table-column>
        <el-table-column prop="legalCompanyName" header-align="center" align="center" label="收费单位" width="100">
        </el-table-column>
        <el-table-column prop="status" header-align="center" align="center" label="结算状态">
          <template slot-scope="scope">
            <div v-if="scope.row.settlementStatus === 0" size="small" type="danger" class="blueMoney">
              未结算
            </div>
            <div v-else size="small" class="greenMoney">已结算</div>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <el-pagination @size-change="sizeChangeHandle" @current-change="currentChangeHandle" :current-page="pageIndex" :page-sizes="[10, 20, 50, 100]" :page-size="pageSize" :total="totalPage" layout="total, sizes, prev, pager, next, jumper">
    </el-pagination>
  </div>
</template>

<script>
export default {
  data () {
    return {
      legalAccountCode: '', // 法人公司编码
      cycleNo: '', // 账单单号
      endBillCycle: '', // 结束账期
      endPaymentTime: '', // 结束支付时间
      orderNo: '', // 订单编号
      startBillCycle: '', // 开始账期
      startPaymentTime: '', // 开始支付时间
      paymentMethod: '', // 订单编号支付方式：1-微信,2-支付宝,3-云闪付,4-快捷支付
      billType: '',
      value5: '',
      dataForm: {
        userName: ''
      },
      options1: [
        {
          value: '0',
          label: '未结算'
        },
        {
          value: '1',
          label: '已结算'
        }
      ],
      settlementStatus: '',
      dataList: [],
      pageIndex: 1,
      pageSize: 20,
      totalPage: 0,
      dataListLoading: false,
      dataListSelections: [],
      addOrUpdateVisible: false,
      value1: '',
      value2: '',
      value3: '',
      value4: '',
      value5: '',
      type: '',
      options: [
        {
          value: '1',
          label: '微信'
        },
        {
          value: '2',
          label: '支付宝'
        },
        // {
        //   value: '3',
        //   label: '云闪付'
        // },
        // {
        //   value: '4',
        //   label: '快捷支付'
        // }
      ],
      options2: [
        {
          value: '1',
          label: '物业费'
        },
        {
          value: '2',
          label: '有偿工单'
        }
      ]
    }
  },
  activated () {
    this.type = localStorage.getItem('type')
    this.cycleNo = this.$route.query.cycleNo
    this.cycleNos = this.$route.query.cycleNos
    this.getDataList()
  },
  methods: {
    // 表格头部提示事件
    fourGrid (h, { column }) {
      return h("span", [
        h("span", column.label),
        h(
          "el-tooltip",
          {
            props: {
              effect: "dark",
              content: "四格缴费的唯一编号，可用于跟四格ERP对账",
              placement: "top",
            },
          },
          [
            h("i", {
              class: "el-icon-question",
              style: "color:#000;margin-left:5px;",
            }),
          ],
          {
            content: "四格缴费的唯一编号，可用于跟四格ERP对账",
          }
        ),
      ]);
    },
    // 表格头部提示事件
    renderHeader (h, { column }) {
      return h('span', [
        h('span', column.label),
        h(
          'el-tooltip',
          {
            props: {
              effect: 'dark',
              content: '包含物业费和有偿工单',
              placement: 'top'
            }
          },
          [
            h('i', {
              class: 'el-icon-question',
              style: 'color:#000;margin-left:5px;'
            })
          ],
          {
            content: '包含物业费和有偿工单'
          }
        )
      ])
    },
    //查询
    demand () {
      this.pageIndex = 1
      this.dataListLoading = true
      this.$http({
        url: this.$http.adornUrl('cassadmin/v1/settlementBill/paymentList'),
        method: 'get',
        params: this.$http.adornParams({
          pageNum: this.pageIndex,
          pageSize: this.pageSize,
          legalAccountCode: this.legalAccountCode,
          cycleNo: this.cycleNo,
          paySerialId: this.dataForm.userName,
          cycleNos: this.cycleNos,
          endBillCycle: this.endBillCycle,
          endPaymentTime: this.value1[1] || '',
          startBillCycle: this.startBillCycle,
          startPaymentTime: this.value1[0] || '',
          paymentMethod: this.value3,
          billType: this.value4,
          settlementStatus: this.settlementStatus
        })
      }).then(({ data }) => {
        if (data.success == 1) {
          console.log(data.data.list)
          this.dataList = data.data.list
          this.totalPage = data.data.total
        } else {
          this.dataList = []
          this.totalPage = 0
        }
        this.dataListLoading = true
      })
    },
    //清空
    empty () {
      this.dataForm.userName = ''
      this.value1 = ''
      this.value3 = ''
      this.value4 = ''
      this.getDataList()
    },
    // 获取数据列表
    getDataList () {
      this.dataListLoading = true
      this.$http({
        url: this.$http.adornUrl('cassadmin/v1/settlementBill/paymentList'),
        method: 'get',
        params: this.$http.adornParams({
          pageNum: this.pageIndex,
          pageSize: this.pageSize,
          legalAccountCode: this.legalAccountCode,
          cycleNo: this.cycleNo,
          paySerialId: this.paySerialId,
          cycleNos: this.cycleNos,
          endBillCycle: this.endBillCycle,
          endPaymentTime: this.endPaymentTime,
          orderNo: this.orderNo,
          startBillCycle: this.startBillCycle,
          startPaymentTime: this.startPaymentTime,
          paymentMethod: this.paymentMethod,
          billType: this.billType,
          settlementStatus: this.settlementStatus
        })
      }).then(({ data }) => {
        if (data.success == 1) {
          console.log(data.data.list)
          this.dataList = data.data.list
          this.totalPage = data.data.total
        } else {
          this.dataList = []
          this.totalPage = 0
        }
        this.dataListLoading = false
      })
    },
    // 每页数
    sizeChangeHandle (val) {
      this.pageSize = val
      this.pageIndex = 1
      this.dataListLoading = true
      this.$http({
        url: this.$http.adornUrl('cassadmin/v1/settlementBill/paymentList'),
        method: 'get',
        params: this.$http.adornParams({
          pageNum: this.pageIndex,
          pageSize: this.pageSize,
          legalAccountCode: this.legalAccountCode,
          cycleNo: this.cycleNo,
          paySerialId: this.dataForm.userName,
          cycleNos: this.cycleNos,
          endBillCycle: this.endBillCycle,
          endPaymentTime: this.value1[1] || '',
          // orderNo: this.dataForm.userName,
          startBillCycle: this.startBillCycle,
          startPaymentTime: this.value1[0] || '',
          paymentMethod: this.value3,
          billType: this.value4,
          settlementStatus: this.settlementStatus
        })
      }).then(({ data }) => {
        if (data.success == 1) {
          console.log(data.data.list)
          this.dataList = data.data.list
          this.totalPage = data.data.total
        } else {
          this.dataList = []
          this.totalPage = 0
        }
        this.dataListLoading = true
      })
    },
    // 当前页
    currentChangeHandle (val) {
      this.pageIndex = val
      this.dataListLoading = true
      this.$http({
        url: this.$http.adornUrl('cassadmin/v1/settlementBill/paymentList'),
        method: 'get',
        params: this.$http.adornParams({
          pageNum: this.pageIndex,
          pageSize: this.pageSize,
          legalAccountCode: this.legalAccountCode,
          cycleNo: this.cycleNo,
          paySerialId: this.dataForm.userName,
          cycleNos: this.cycleNos,
          endBillCycle: this.endBillCycle,
          endPaymentTime: this.value1[1] || '',
          // orderNo: this.dataForm.userName,
          startBillCycle: this.startBillCycle,
          startPaymentTime: this.value1[0] || '',
          paymentMethod: this.value3,
          billType: this.value4,
          settlementStatus: this.settlementStatus
        })
      }).then(({ data }) => {
        if (data.success == 1) {
          console.log(data.data.list)
          this.dataList = data.data.list
          this.totalPage = data.data.total
        } else {
          this.dataList = []
          this.totalPage = 0
        }
        this.dataListLoading = true
      })
    },
    // 周期
    TimeYue (e) {
      this.pageIndex = 1
      if (e) {
        this.startBillCycle = e[0]
        this.endBillCycle = e[1]
      } else {
        this.startBillCycle = ''
        this.endBillCycle = ''
      }
      this.getDataList()
    },
    // 状态
    status1 (e) {
      this.pageIndex = 1
      this.settlementStatus = e
      this.getDataList()
    },
    // 导出excel
    exportExcel () {
      if (this.value1 == '') {
        var start = this.value1
        var end = this.value1
      } else {
        var start = this.value1[0]
        var end = this.value1[1]
      }
      window.location.href =
        `https://api.xstarlife.com/cassadmin/v1/settlementBill/downloadPaymentList?&cycleNo=${this.cycleNo}&endPaymentTime=${end}&paySerialId=${this.dataForm.userName}&billType=${this.value4}&startPaymentTime=${start}&paymentMethod=${this.value3}`
    },
  }
}
</script>
<style scoped>
.balance-searchMoney {
  display: flex;
  align-items: center;
}
.input {
  flex: 1;
  margin-left: 5px;
}
.export {
  margin-top: 30px;
  background-color: #fff;
  padding: 20px;
  border-radius: 6px;
}
</style>
